import 'package:boss/ui/page/analysis/page/analysisDetail/analysis_detail_page.dart';
import 'package:boss/ui/page/analysis/page/analysisDetail/model/analysis_detail_type.dart';
import 'package:boss/ui/page/analysis/provider/analysis_provider.dart';
import 'package:boss/ui/page/analysis/widget/time_row.dart';
import 'package:boss/ui/widget/charts/bar/bar_chart.dart';
import 'package:boss/ui/widget/loader/loader_pull_refresh.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'staff_card.dart';

class StaffBrowser extends StatefulWidget {
  @override
  _StaffBrowserState createState() => _StaffBrowserState();
}

class _StaffBrowserState extends State<StaffBrowser> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);

    return Consumer<AnalysisProvider>(
      builder: (context, provider, child) {
        return LoaderPullRefresh(
          refreshTask: provider.queryStaff,
          builder: (context) {
            return SingleChildScrollView(
              padding: EdgeInsets.symmetric(
                horizontal: 30.w,
                vertical: 30.w,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  TimeRow(provider.timerRangeText),
                  StaffCard<double>(
                    title: '店内销售额排行',
                    data: provider.storeSellSort,
                    unit: '元',
                  ),
                  StaffCard<double>(
                    title: '小费收入排名',
                    data: provider.tipSort,
                    titleTip: '按照员工小费收入金额从高到低排序，没有计算到员工上面的那部分全部按照【其他】统计；人员大于N个（宽度固定可显示人数）左右拖动可查看全部人员数据，否则不显示拖动条；',
                    onActionTap: () {
                      Navigator.pushNamed(context, AnalysisDetailPage.pageName, arguments: {
                        'type': AnalysisDetailType.tipSort,
                        'startTime': provider.startTime,
                        'endTime': provider.endTime,
                      });
                    },
                    unit: '元',
                  ),
                  StaffCard<int>(
                    title: '客户排行',
                    data: provider.customerSort,
                    unit: '人',
                  ),
                  StaffCard<double>(
                    title: '外卖销售额排行',
                    data: provider.takeoutSort,
                    unit: '元',
                  ),
                  StaffCard<int>(
                    title: '预定单数排行',
                    data: provider.bookListSort,
                    unit: '单',
                    onActionTap: () {
                      Navigator.pushNamed(context, AnalysisDetailPage.pageName, arguments: {
                        'type': AnalysisDetailType.book,
                        'startTime': provider.startTime,
                        'endTime': provider.endTime,
                      });
                    },
                  ),
                  StaffCard<double>(
                    title: '菜品提成排行',
                    titleTip: '仅统计堂食菜品销售提成，没有绑定到员工的菜品不算提成，销售额全部归门店所有',
                    data: provider.commodityCommissionSort,
                    onActionTap: () {
                      Navigator.pushNamed(context, AnalysisDetailPage.pageName, arguments: {
                        'type': AnalysisDetailType.commodityCommissionSort,
                        'startTime': provider.startTime,
                        'endTime': provider.endTime,
                      });
                    },
                    unit: '元',
                  ),
                  StaffCard<double>(
                    title: '预定提成排行',
                    titleTip: '员工预定客到提成金额排行',
                    data: provider.staffCommissionList,
                    unit: '元',
                  ),
                  StaffCard<double>(
                    title: '劵类提成排行  ',
                    titleTip: '统计门店员工派劵并核销提成金额数',
                    data: provider.couponIncomeRankList,
                    unit: '元',
                  ),
                  StaffCard<int>(
                    title: '员工好评排行',
                    titleTip: '仅堂食用餐中评价了该员工服务的好评数',
                    data: provider.commentListSort,
                    unit: '数',
                  ),
                ],
              ),
            );
          },
        );
      },
    );
  }

  @override
  bool get wantKeepAlive => true;
}
